<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <father-page></father-page>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data() {
        return {
          name: 'CommonHead1'
        }
      }
    });
    // 子组件
    const ChildPage = {
      template: `
        <div>
          <h3>这是子组件</h3>  
          {{ a }}
          <hr/>
          {{ b }}
          <hr/>
          {{ c }}
          <hr/>
          {{ d }}
          <hr/>
          {{ e }}
        </div>
      `,
      // props验证
      props: {
        // 只验证数据类型
        a: Number,
        // 只验证类型，类型可以是多个
        b: [Number, String],
        // 既验证规则 要求必须传值
        c: {
          type: Number,
          required: true
        },
        // 验证规则 不传有默认值
        d: {
          type: String,
          default: '这是默认值'
        },
        e: {
          type: Array,
          default: () => [2,3,4,5]
        },
        // 自定义校验
        f: {
          validator: value => {
            // 返回布尔值 true验证通过 false 则不通过
            if (value === '小明'){
              return true
            } else {
              return false
            }
          }
        }
      }
     
    }
    // 父组件
    const FatherPage = {
      template: `
        <div>
          <h2>这是父组件</h2>  
          <hr/>
          <child-page :a="10" :b="[1,2,3]" f="小红"></child-page>
        </div>
      `,
      data() {
        return {
         
        }
      },
      components: {
        ChildPage
      }
    }
    app.component('FatherPage', FatherPage)

    app.mount('#app')
  </script>
</body>
</html>